<template>
    
    <div class="layout">
    
        <el-container id="container">
    
            <el-header style="background-color: white;box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);">
              <div>
                <h3 style="float: left;color: #172b4d;height: 100%;">高校云会议</h3>
                <el-tag v-if="userId!=='1'" style="float: left;width: 150px;height: 30px;margin-top: 18px;margin-left: 10px">{{uniName}}</el-tag>
              </div>
              <el-dropdown style="float:right;margin-top: 10px;">
                <div>
                  <el-avatar :src="avatarUrl" >{{user.name}}</el-avatar>
                </div>
                <template #dropdown>
                  <el-dropdown-menu>
                    <el-dropdown-item @click="to('/main/user')">修改密码</el-dropdown-item>
                    <el-dropdown-item @click="to('/')">退出登录</el-dropdown-item>
                  </el-dropdown-menu>
                </template>
              </el-dropdown>
              <el-menu
                  router
                  style="float:right; display: inline-block;width: 500px"
                  :default-active="$route.path"
                  class="el-menu-demo"
                  mode="horizontal"
                  background-color="white"
                  text-color="#172b4d"
                  active-text-color="#409EFF"
              >
                <el-menu-item v-if="menus.length===0" index="/main/university/manage">高校管理</el-menu-item>
                <el-menu-item v-if="menus.length===0" index="/main/meeting">会议管理</el-menu-item>
                <el-menu-item v-if="menus.length===0" index="/main/teacher/account">教师管理</el-menu-item>
                <el-menu-item v-if="menus.length===0" index="/main/student/account">学生管理</el-menu-item>
                <el-menu-item v-for="menu in menus"
                              :index="menu.home">{{menu.menuGroup}}</el-menu-item>
              </el-menu>
            </el-header>
            <el-container>
                  <router-view style="width:100%;height: 100%;" name="main"/>
            </el-container>
        </el-container>
    </div>
  </template>
  
  <script>
  import router from '../../router'
  import { mapMutations, mapState } from 'vuex'
  import {ArrowDown} from "@element-plus/icons-vue";

  export default {
    components: {ArrowDown},
    created: function() {
      this.$http.get("/user/menu/select?userId="+this.userId)
          .then((response) => {
            if (response.data.code === 200) {
              this.menus = response.data.data;
              console.log(this.menus);
            } else {
              this.$message.error(response.data.msg);
            }
          });
    },
    computed:{
        ...mapState(['user','avatarUrl']),
  
      },
    data: function() {
        return {
            userId:localStorage.getItem("userId"),
            menus:[],
            uniName:localStorage.getItem("uniName"),
            uniId:localStorage.getItem("uniId")
        }
    },
    mounted() {
      this.$http.get("/user/menu/select?userId="+this.userId)
          .then((response) => {
            if (response.data.code === 200) {
              this.menus = response.data.data;
              console.log(this.menus);
            } else {
              this.$message.error(response.data.msg);
            }
      });
    },
    methods: {
        ...mapMutations(['setUser']),
        to(value){
          router.push(value);
        }
    }
  }
  </script>
  <style scoped>
  .layout {
    position: fixed;
    width: 100%;
    height: 100%;
    top: 60px;
    left: 0;
    background: transparent;
  }

  .el-menu-demo {
    border-bottom: none;
  }

  .btn{
    width: 200px;
    height: 100%;
    margin-left: 25px;
    border-radius: 5px;
    color:white;
    size: 10px;
    line-height: 60px;
    background: #45abab;
  }
  
  #container{
    position: fixed;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
  }
  
  </style>